# coding:utf-8

import random
import math
from timeit import timeit

def sum_iter_float():
    iterable_float = \
        [0.7942922833923649,
         0.07132506742580746,
         0.22021054089439906,
         0.7310312969923531,
         0.21085041242646063,
         0.5477468962207974,
         0.4427295642418272,
         0.4966629840876564,
         0.24027098283581427,
         0.26969157782290953,
         0.26219813106470513,
         0.040256328809593955,
         0.06548970621972161,
         0.42580295707777105,
         0.9117621088226956,
         0.25463015260355104,
         0.035568150172725965,
         0.9374207199152398,
         0.06303972359498855,
         0.6924674826099806]
    iter_float = iter(iterable_float)

    return sum(iter_float)

def sum_iter_int():


    iterable_int = [63, 55, 15, 32, 91, 17, 93, 7, 4, 55, 98, 40, 76, 77, 12, 93, 64, 78, 100, 62]
    iter_int = iter(iterable_int)
    return sum(iter_int)

def sum_iterable_float():
    iterable_float = \
        [0.7942922833923649,
         0.07132506742580746,
         0.22021054089439906,
         0.7310312969923531,
         0.21085041242646063,
         0.5477468962207974,
         0.4427295642418272,
         0.4966629840876564,
         0.24027098283581427,
         0.26969157782290953,
         0.26219813106470513,
         0.040256328809593955,
         0.06548970621972161,
         0.42580295707777105,
         0.9117621088226956,
         0.25463015260355104,
         0.035568150172725965,
         0.9374207199152398,
         0.06303972359498855,
         0.6924674826099806]


    return sum(iterable_float)

def sum_iterable_int():


    iterable_int = [63, 55, 15, 32, 91, 17, 93, 7, 4, 55, 98, 40, 76, 77, 12, 93, 64, 78, 100, 62]

    return sum(iterable_int)



def fsum_iter_float():
    iterable_float = \
        [0.7942922833923649,
         0.07132506742580746,
         0.22021054089439906,
         0.7310312969923531,
         0.21085041242646063,
         0.5477468962207974,
         0.4427295642418272,
         0.4966629840876564,
         0.24027098283581427,
         0.26969157782290953,
         0.26219813106470513,
         0.040256328809593955,
         0.06548970621972161,
         0.42580295707777105,
         0.9117621088226956,
         0.25463015260355104,
         0.035568150172725965,
         0.9374207199152398,
         0.06303972359498855,
         0.6924674826099806]

    iter_float = iter(iterable_float)

    return math.fsum(iter_float)

def fsum_iter_int():


    iterable_int = [63, 55, 15, 32, 91, 17, 93, 7, 4, 55, 98, 40, 76, 77, 12, 93, 64, 78, 100, 62]
    iter_int = iter(iterable_int)
    return math.fsum(iter_int)

def fsum_iterable_float():
    iterable_float = \
        [0.7942922833923649,
         0.07132506742580746,
         0.22021054089439906,
         0.7310312969923531,
         0.21085041242646063,
         0.5477468962207974,
         0.4427295642418272,
         0.4966629840876564,
         0.24027098283581427,
         0.26969157782290953,
         0.26219813106470513,
         0.040256328809593955,
         0.06548970621972161,
         0.42580295707777105,
         0.9117621088226956,
         0.25463015260355104,
         0.035568150172725965,
         0.9374207199152398,
         0.06303972359498855,
         0.6924674826099806]


    return math.fsum(iterable_float)

def fsum_iterable_int():


    iterable_int = [63, 55, 15, 32, 91, 17, 93, 7, 4, 55, 98, 40, 76, 77, 12, 93, 64, 78, 100, 62]

    return math.fsum(iterable_int)

def main():

    loop_num = 100000

    # sum(iter)
    # iter_float
    print("sum_iter_float time : ",timeit(stmt="sum_iter_float()",
                                          setup="from __main__ import sum_iter_float",
                                          number=loop_num))
    print("sum_iter_float: ",sum_iter_float())

    # iter_int
    print("sum_iter_int time : ", timeit(stmt="sum_iter_int()",
                                         setup="from __main__ import sum_iter_int",
                                         number=loop_num))
    print("sum_iter_int: ", sum_iter_int())

    # iterable_float
    print("sum_iterable_float time : ", timeit(stmt="sum_iterable_float()",
                                               setup="from __main__ import sum_iterable_float",
                                               number=loop_num))
    print("sum_iterable_float : ", sum_iterable_float())

    # iterable_int
    print("sum_iterable_int time : ", timeit(stmt="sum_iterable_int()",
                                             setup="from __main__ import sum_iterable_int",
                                             number=loop_num))
    print("sum_iterable_int : ", sum_iterable_int())


    # math.fsum(iter)
    # iter_float
    print("fsum_iter_float time : ", timeit(stmt="fsum_iter_float()",
                                            setup="from __main__ import fsum_iter_float;import math",
                                            number=loop_num))
    print("fsum_iter_float: ", fsum_iter_float())

    # iter_int
    print("fsum_iter_int time : ", timeit(stmt="fsum_iter_int()",
                                          setup="from __main__ import fsum_iter_int;import math",
                                          number=loop_num))
    print("fsum_iter_int: ", fsum_iter_int())

    # iterable_float
    print("fsum_iterable_float time : ", timeit(stmt="fsum_iterable_float()",
                                                setup="from __main__ import fsum_iterable_float;import math",
                                                number=loop_num))
    print("fsum_iterable_float: ", fsum_iter_float())

    # iterable_int
    print("fsum_iterable_int time : ", timeit(stmt="fsum_iterable_int()",
                                              setup="from __main__ import fsum_iterable_int;import math",
                                              number=loop_num))
    print("fsum_iterable_int: ", fsum_iterable_int())

if __name__ == '__main__':
    main()

